package com.jinkaimen.kqb.application;

import android.content.Intent;
import android.util.Log;

import com.ht.baselibs.application.HTApplication;
import com.ht.baselibs.retrofit.RequestUtils;
import com.ht.baselibs.retrofit.converter.fastjson.FastJsonResponseBodyConverter;
import com.ht.baselibs.retrofit.interceptor.AddCookiesInterceptor;
import com.ht.baselibs.retrofit.interceptor.SaveCookiesInterceptor;
import com.iflytek.cloud.SpeechConstant;
import com.iflytek.cloud.SpeechUtility;
import com.jinkaimen.kqb.constant.HttpConfig;
import com.jinkaimen.kqb.http.ConsultInterceptor;
import com.jinkaimen.kqb.http.ParameterInterceptor;
import com.jinkaimen.kqb.service.PushService;
import com.squareup.leakcanary.LeakCanary;
import com.tencent.smtt.sdk.QbSdk;
import com.umeng.analytics.MobclickAgent;
import com.umeng.socialize.Config;
import com.umeng.socialize.PlatformConfig;
import com.umeng.socialize.UMShareAPI;

import java.util.HashMap;

public class AppApplication extends HTApplication {
    public static HashMap<String, Object> tempMap;

    @Override
    public void onCreate() {
        super.onCreate();
        Intent downloadIntent = new Intent(this, PushService.class);
        this.startService(downloadIntent);
        tempMap = new HashMap<>();
        MobclickAgent.setCatchUncaughtExceptions(!IS_DEBUG_MODE);
        SpeechUtility.createUtility(this, SpeechConstant.APPID + "=586db9ce");
        RequestUtils.initInterceptors(new ConsultInterceptor(), new ParameterInterceptor(), new AddCookiesInterceptor(this), new SaveCookiesInterceptor(this));
        //友盟分享
        Config.DEBUG = true;
        UMShareAPI.get(this);
        //x5 webview 框架
        QbSdk.PreInitCallback cb = new QbSdk.PreInitCallback() {

            @Override
            public void onViewInitFinished(boolean arg0) {
                // TODO Auto-generated method stub
                //x5內核初始化完成的回调，为true表示x5内核加载成功，否则表示x5内核加载失败，会自动切换到系统内核。
                Log.d("app", " onViewInitFinished is " + arg0);
            }

            @Override
            public void onCoreInitFinished() {
                // TODO Auto-generated method stub
            }
        };
        //x5内核初始化接口
        QbSdk.initX5Environment(getApplicationContext(), cb);

        LeakCanary.install(this);
    }

    //友盟配置
    {
        //各个平台的配置，建议放在全局Application或者程序入口

        PlatformConfig.setQQZone("1106341078", "EK61VRyE4fb0Aa2l");
//        PlatformConfig.setWeixin("wx9a1cbbc9c5b82eb7", "18973c9f67fa80a4b5df8d456b4dc019");
        PlatformConfig.setWeixin("wxcd3160e3a63a9046", "2cf35df86c448e7f5866a147825225e5");

    }

    @Override
    protected boolean isDebugMode() {

        return true;
    }

    @Override
    protected String getHost() {
        return HttpConfig.BASE_URL;
    }

    @Override
    protected FastJsonResponseBodyConverter.DecodeService getDecodeService() {
        return null;
    }

    public static Object getTempData(String key) {
        return tempMap.get(key);
    }

    public static void putTempData(String key, Object value) {
        tempMap.put(key, value);
    }

//    IntentFilter filter = new IntentFilter(Intent.ACTION_TIME_TICK);
//    MyBroadcastReceiver receiver = new MyBroadcastReceiver();
//    registerReceiver(receiver, filter);

}
